/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

/**
 *
 * @author LUIS
 */
import java.util.ArrayList;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import model.*;

@XmlRootElement(name="Map")
@XmlAccessorType (XmlAccessType.FIELD)
public class XmlCreator {
	@XmlElement(name="Cell")
	ArrayList<Cell> arrCell=null;
	
	public ArrayList<Cell> getArrCell() {
		return arrCell;
	}
	
	public void setArrCell(ArrayList<Cell> arrCell) {
		this.arrCell = arrCell;
	}
	
	public void mapToArrayList(Map map){
		int x=map.getColumn();
		int y=map.getRow();
		
		for(int j=0;j<y;j++){
			for(int i=0;i<x;i++){
				arrCell.add(map.getCell(i, j));
			}
		}
	}
	
	public Map arrayListToMap(){
		int count=arrCell.size();
		Cell tc=arrCell.get(count-1);
		int x=tc.getX();
		int y=tc.getY();
		int index=0;
		Map map=new Map(x+1,y+1);
		for(int j=0;j<y+1;j++){
			for(int i=0;i<x+1;i++){
				map.setCell(i, j, arrCell.get(index));
				index++;
			}
		}
		return map;
		
	}
}
